/*
 * Copyright (c) 2020, 2023, 3044483124@qq.com All rights reserved.
 *
 */
package cn.itcast;

import java.io.*;

/**
 * <p>Project: JavaStudy - File2
 * <p>Powered by jiangbo On 2023-01-03
 * 14:39:11
 * <p>Created by IntelliJ IDEA
 *
 * @author jiangbo [3044483124@qq.com]
 * @version 1.0
 * @since 8/17
 */
public class File2 {
    public static void main(String[] args) {
        ////建立文件,并写入内容 文件输出流（文件输出字节流）
        try(var f = new FileOutputStream("u.dat",true)){
            f.write("hello中文".getBytes("utf-8"));
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        try(var out = new PrintWriter("usr.dat")){
        //将当前系统的日期+.jpg 字符串并写入usr.dat文件中。并自动关闭释放占用的资源
            out.printf("%tF.jpg",System.currentTimeMillis());
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }

        //读取文件
        try(var reader = new FileReader("u.dat")){
            while(reader.ready()) {
                System.out.print((char)reader.read());
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        //删除
//        File file  =new File("u.dat");
//        File file2  =new File("usr.dat");
//        file.delete();
//        file2.delete();

    }

}


